﻿using System;

namespace LeRenard.ScriptWars.Model.Scripting.OperationParameterTypeValueConverters
{
    /// <summary>
    /// Abstract base implementation of <see cref="IOperationParameterTypeValueConverter"/>.
    /// </summary>
    public abstract class OperationParameterTypeValueConverter<T> : IOperationParameterTypeValueConverter<T>
    {
        #region Properties
        /// <summary>
        /// Gets the parameter type it converts to/from.
        /// </summary>
        public OperationParameterType ParameterType { get { return _parameterType; } }
        private readonly OperationParameterType _parameterType;

        /// <summary>
        /// Gets the .Net <see cref="Type"/> it converts to/from.
        /// </summary>
        public Type Type { get { return _type; } }
        private readonly Type _type;
        #endregion

        #region Construction
        /// <summary>
        /// Creates a new <see cref="OperationParameterTypeValueConverter"/> object.
        /// </summary>
        internal OperationParameterTypeValueConverter(OperationParameterType parameterType)
        {
            _type = typeof(T);
            _parameterType = parameterType;
        }
        #endregion

        #region Methods
        /// <summary>
        /// Converts the raw script value to a .Net type value.
        /// </summary>
        /// <param name="parameterValue">The value to be converted.</param>        
        public abstract T ConvertFromScriptValue(string parameterValue);

        /// <summary>
        /// Converts a .Net type value to the raw script value.
        /// </summary>
        /// <param name="parameterValue">the value to be converted.</param>        
        public abstract string ConvertToScriptValue(T parameterValue);
        #endregion
    }
}
